package deep.projects.newsapp.activities;

import android.os.Bundle;
import android.widget.EditText;

import com.wuxinwudai.adlg.ProgressDialog;
import com.wuxinwudai.android.beans.JsonRequestResult;
import com.wuxinwudai.android.util.ToastUtils;
import com.zhy.http.okhttp.OkHttpUtils;
import com.zhy.http.okhttp.callback.Callback;

import org.json.JSONObject;



import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import deep.projects.newsapp.R;
import deep.projects.newsapp.app.Urls;
import okhttp3.Call;
import okhttp3.Response;

/**
 * @author 吾心无待 于2016年03月05日
 */
public class FeedbackActivity extends BaseLayoutActivity {
    @BindView(R.id.et_feedback) EditText metFeedback;
    @BindView(R.id.et_contact) EditText metContact;
    protected ProgressDialog dialog;
    @OnClick(R.id.btn_feedback) void onFeedback(){
        final String content = metFeedback.getText().toString();
        if ( content.length() < 6){
            ToastUtils.showShort(FeedbackActivity.this, R.string.msg_feedback_too_short);
            return;
        }
        OkHttpUtils.post()
                .url(Urls.POST_ITF_FEEDBACK)
                .addParams("content", content)
                .addParams("contact",metContact.getText().toString())
                .build()
                .execute(new Callback<JsonRequestResult>() {
                    @Override
                    public JsonRequestResult parseNetworkResponse(Response response) throws Exception {
                        return JsonRequestResult.from(new JSONObject(response.body().string()));
                    }

                    @Override
                    public void onError(Call call, Exception e) {
                        dialog.error(e.getMessage());
                    }

                    @Override
                    public void onResponse(JsonRequestResult response) {
                        dialog.success("您的反馈已将提交成功！");
                    }
                });
        dialog.show();
    }



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ButterKnife.bind(this);
        tvTitle.setText(R.string.title_activity_feedback);
    }

    @Override
    public int getLayoutId() {
        return R.layout.activity_feedback;
    }
}
